package com.hns.can.report.service;

import java.math.BigDecimal;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.hns.can.report.vo.DrvBehaviorFeatureCompareVo;
import com.hns.can.report.vo.DrvBehaviorFeatureDetailVo;
import com.hns.can.report.vo.DrvBehaviorFeatureTypeVo;
import com.hns.can.report.vo.DrvBehaviorFeatureVo;
import com.hns.can.report.vo.DrvBehaviorImproveVo;
import com.hns.can.report.vo.DrvBehaviorModelDataVo;
import com.hns.can.report.vo.DrvBehaviorScoreAvgVo;
import com.hns.can.report.vo.DrvBehaviorScoreHotVo;
import com.hns.can.report.vo.DrvBehaviorScoreLevelVo;
import com.hns.can.report.vo.DrvBehaviorScorePointVo;
import com.hns.can.report.vo.DrvBehaviorRatioVo;
import com.hns.can.report.vo.DrvBehaviorRangeVo;
import com.hns.can.report.vo.DrvBehaviorScoreHotLevelVo;
import com.hns.can.report.vo.DrvBehaviorScoreRatioVo;
import com.hns.can.report.vo.DrvBehaviorScoreSingleVo;
import com.hns.can.report.vo.DrvBehaviorScoreSortVo;
import com.hns.can.report.vo.DrvBehaviorScoreTrendVo;
import com.hns.can.report.vo.DrvInfoVo;
import com.hns.can.report.vo.TimeRangeVo;
import com.hns.frame.mybatis.Pagination;
import com.hns.frame.service.CommonService;
import com.hns.tool.pub.CommUtil;
import com.hns.tool.pub.DateTool;
import com.hns.tool.pub.PubUtil;

/**
 * @ClassName: DriverBehaviorService
 * @Description: 驾驶行为统计
 * @author zhangl
 * @email victor_007@126.com
 * @date 2016年12月15日 上午9:43:31
 */
@Service
public class DriverBehaviorService extends CommonService {

    /**
     * @Title: convertDate
     * @Description: 根据时间条件类型，转换需要统计的开始时间和结束时间
     * @author zhangl
     * @param dateType 02:昨天 ，03：近7天， 04：本月，05：上月，06：今年，07:去年
     * @param index 1：当期；-1：前期
     * @param chartType 图表类型 01：行为分类；02：分数； 03：驾驶行为
     * @param lineId 线路id
     * @return Map<String,Object>
     * @throws ParseException
     */
    public Map<String, Object> convertDate(String dateType, int index, String chartType, String lineId) throws ParseException {
        Map<String, Object> dateMap = new HashMap<String, Object>();
        Date nowDate = new Date();
        String beginTime = "";
        String endTime = "";
        Date timePoint = null;
        String specifyDate = "";
        Map<String, Object> maxDateMap = null;
        String maxDate = "";
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("lineId", lineId);

        switch (dateType) {
        case "02":
            timePoint = DateTool.calculateByDate(nowDate, -1);
            specifyDate = DateTool.date2String("yyyy-MM-dd", timePoint);
            params.put("specifyDate", specifyDate);
            switch (chartType) {// 取得查询时间点
            case "01":
                maxDateMap = this.getMaxDateByBehavior(params);
                break;
            case "02":
                maxDateMap = this.getMaxDateByScore(params);
                break;
            case "03":
                maxDateMap = this.getMaxDateByFeature(params);
                break;
            }
            if (maxDateMap != null) {
                maxDate = maxDateMap.get("MAXDATE").toString();
                if (index == 1) {
                    beginTime = maxDate;
                    endTime = maxDate;
                } else {
                    beginTime = DateTool.calculateByDate(maxDate, -1);
                    endTime = DateTool.calculateByDate(maxDate, -1);
                }
            }
            break;
        case "03":
            timePoint = nowDate;
            specifyDate = DateTool.date2String("yyyy-MM-dd", timePoint);
            params.put("specifyDate", specifyDate);
            switch (chartType) {// 取得查询时间点
            case "01":
                maxDateMap = this.getMaxDateByBehavior(params);
                break;
            case "02":
                maxDateMap = this.getMaxDateByScore(params);
                break;
            case "03":
                maxDateMap = this.getMaxDateByFeature(params);
                break;
            }
            if (maxDateMap != null) {
                maxDate = maxDateMap.get("MAXDATE").toString();
                if (index == 1) {
                    beginTime = DateTool.calculateByDate(maxDate, -6);
                    endTime = maxDate;
                } else {
                    beginTime = DateTool.calculateByDate(maxDate, -13);
                    endTime = DateTool.calculateByDate(maxDate, -7);
                }
            }
            break;
        case "04":
            timePoint = nowDate;
            if (index == 1) {
                beginTime = DateTool.getFirstDayOfMonth(DateTool.date2String("yyyy-MM-dd", timePoint));
                endTime = DateTool.getLastDayOfMonth(DateTool.date2String("yyyy-MM-dd", timePoint));
            } else {
                timePoint = DateTool.calculateByMonth(timePoint, -1);
                beginTime = DateTool.getFirstDayOfMonth(DateTool.date2String("yyyy-MM-dd", timePoint));
                endTime = DateTool.getLastDayOfMonth(DateTool.date2String("yyyy-MM-dd", timePoint));
            }
            break;
        case "05":
            timePoint = DateTool.calculateByMonth(nowDate, -1);
            if (index == 1) {
                beginTime = DateTool.getFirstDayOfMonth(DateTool.date2String("yyyy-MM-dd", timePoint));
                endTime = DateTool.getLastDayOfMonth(DateTool.date2String("yyyy-MM-dd", timePoint));
            } else {
                timePoint = DateTool.calculateByMonth(timePoint, -1);
                beginTime = DateTool.getFirstDayOfMonth(DateTool.date2String("yyyy-MM-dd", timePoint));
                endTime = DateTool.getLastDayOfMonth(DateTool.date2String("yyyy-MM-dd", timePoint));
            }
            break;
        case "06":
            timePoint = nowDate;
            if (index == 1) {
                beginTime = DateTool.date2String("yyyy", timePoint)+"-01-01";
                endTime = DateTool.date2String("yyyy", timePoint)+"-12-31";
            } else {
                timePoint = DateTool.calculateByYear(timePoint, -1);
                beginTime = DateTool.date2String("yyyy", timePoint)+"-01-01";
                endTime = DateTool.date2String("yyyy", timePoint)+"-12-31";
            }
            break;
        case "07":
            timePoint = DateTool.calculateByYear(nowDate, -1);
            if (index == 1) {
                beginTime = DateTool.date2String("yyyy", timePoint)+"-01-01";
                endTime = DateTool.date2String("yyyy", timePoint)+"-12-31";
            } else {
                timePoint = DateTool.calculateByYear(timePoint, -1);
                beginTime = DateTool.date2String("yyyy", timePoint)+"-01-01";
                endTime = DateTool.date2String("yyyy", timePoint)+"-12-31";
            }
            break;
        }
        dateMap.put("beginTime", beginTime);
        dateMap.put("endTime", endTime);
        return dateMap;
    }

    /**
     * @Title: getMaxDateByBehavior
     * @Description: 驾驶员行为分类 查询离指定时间最近的时间
     * @author zhangl
     * @param params
     * @return String
     */
    @SuppressWarnings({ "unchecked" })
    public Map<String, Object> getMaxDateByBehavior(Map<String, Object> params) {
        Map<String, Object> map = (Map<String, Object>) this.sqlMapDao.selectOne("driverBehavior.getMaxDateByBehavior", params);
        return map;
    }

    /**
     * @Title: getMaxDateByScore
     * @Description: 驾驶员分数 查询离指定时间最近的时间
     * @author zhangl
     * @param params
     * @return String
     */
    @SuppressWarnings({ "unchecked" })
    public Map<String, Object> getMaxDateByScore(Map<String, Object> params) {
        Map<String, Object> map = (Map<String, Object>) this.sqlMapDao.selectOne("driverBehavior.getMaxDateByScore", params);
        return map;
    }
    
    /**
     * 
     * @Title:  getMaxDateByFeature
     * @Description: 驾驶行为特征 查询离指定时间最近的时间
     * @author zhangl
     * @param params
     * @return
     * Map<String,Object>
     */
    @SuppressWarnings({ "unchecked" })
    public Map<String, Object> getMaxDateByFeature(Map<String, Object> params) {
        Map<String, Object> map = (Map<String, Object>) this.sqlMapDao.selectOne("driverBehavior.getMaxDateByFeature", params);
        return map;
    }
    
    /**
     * @Title: getTimeRange
     * @Description: 根据类型获取时间范围
     * @author zhangl
     * @param params
     * @return TimeRangeVo
     */
    @SuppressWarnings({ "unchecked" })
    public TimeRangeVo getTimeRange(Map<String, Object> params) {
        Map<String, Object> mapCurrent = (Map<String, Object>) this.sqlMapDao.selectOne("driverBehavior.getTimeRange", params);
        TimeRangeVo timeRangeVo = (TimeRangeVo) PubUtil.convertMapToObject(mapCurrent, TimeRangeVo.class);
        return timeRangeVo;
    }
    
    /**
     * 
     * @Title:  getDrvList
     * @Description: 获取驾驶员列表
     * @author zhangl
     * @param params
     * @return
     * List<DrvInfoVo>
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public List<DrvInfoVo> getDrvList(Map<String, Object> params) {
        List<Map> dataMap = this.sqlMapDao.selectList("driverBehavior.getDrvList", params);
        List<DrvInfoVo> dataList = PubUtil.convertListMapToObject(dataMap, DrvInfoVo.class);
        return dataList;
    }

    /**
     * @Title: statBeorRatioRange
     * @Description: 驾驶行为分类占比、增长率
     * @author zhangl
     * @param params
     * @return BehaviorProportionVo
     */
    @SuppressWarnings({ "unchecked" })
    public Map<String, Object> statBeorRatioRange(Map<String, Object> params) {
        Map<String, Object> map = new HashMap<String, Object>();
        DrvBehaviorRatioVo beorRaCurrent = this.statBeorRaByClusType(params, 1);// 当期
        double ct0 = beorRaCurrent.getClusType0().doubleValue();
        double ct1 = beorRaCurrent.getClusType1().doubleValue();
        double ct2 = beorRaCurrent.getClusType2().doubleValue();

        DrvBehaviorRatioVo beorRAProphase = this.statBeorRaByClusType(params, -1);// 前期
        double pt0 = beorRAProphase.getClusType0().doubleValue();
        double pt1 = beorRAProphase.getClusType1().doubleValue();
        double pt2 = beorRAProphase.getClusType2().doubleValue();

        DrvBehaviorRangeVo rangeVo = new DrvBehaviorRangeVo();// 增长率
        rangeVo.setClusTypeRange0((ct0 == 0 || pt0 == 0) ? BigDecimal.valueOf(0) : BigDecimal.valueOf(CommUtil.null2Double((pt0 - ct0) / ct0 * 100)));
        rangeVo.setClusTypeRange1((ct1 == 0 || pt1 == 0) ? BigDecimal.valueOf(0) : BigDecimal.valueOf(CommUtil.null2Double((pt1 - ct1) / ct1 * 100)));
        rangeVo.setClusTypeRange2((ct2 == 0 || pt2 == 0) ? BigDecimal.valueOf(0) : BigDecimal.valueOf(CommUtil.null2Double((pt2 - ct2) / ct2 * 100)));
        map.put("beorRaCurrent", beorRaCurrent);
        map.put("rangeVo", rangeVo);
        return map;
    }

    /**
     * @Title: statBeorRaByClusType
     * @Description: 驾驶行为分类占比
     * @author zhangl
     * @param params
     * @return BehaviorProportionVo
     */
    @SuppressWarnings({ "unchecked" })
    public DrvBehaviorRatioVo statBeorRaByClusType(Map<String, Object> params, int index) {
        Map<String, Object> dateMapCurrent = null;
        try {
            dateMapCurrent = this.convertDate(params.get("dateType").toString(), index, "01", params.get("lineId").toString());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        params.putAll(dateMapCurrent);
        Map<String, Object> mapCurrent = (Map<String, Object>) this.sqlMapDao.selectOne("driverBehavior.statBehaviorRatio", params);
        DrvBehaviorRatioVo behaviorRatioVo = (DrvBehaviorRatioVo) PubUtil.convertMapToObject(mapCurrent, DrvBehaviorRatioVo.class);
        return behaviorRatioVo;
    }

    /**
     * @Title: statScoreLevelRatio
     * @Description: 驾驶员分数等级、比率、平均分、临界点 统计
     * @author zhangl
     * @param params
     * @return Map<String,Object>
     */
    @SuppressWarnings({ "unchecked" })
    public Map<String, Object> statScoreLevelRatio(Map<String, Object> params) {
        Map<String, Object> dateMapCurrent = null;
        try {
            dateMapCurrent = this.convertDate(params.get("dateType").toString(), 1, "02", params.get("lineId").toString());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        params.putAll(dateMapCurrent);

        Map<String, Object> dataMap = new HashMap<String, Object>();

        DrvBehaviorScoreLevelVo scoreLevelVo = this.statScoreLevel(params);
        DrvBehaviorScoreRatioVo scoreRatioVo = this.statScoreRatio(params);
        DrvBehaviorScoreAvgVo scoreAvgVo = this.statScoreAvg(params);
        DrvBehaviorScorePointVo scorePointVo = this.statScorePoint(params);

        dataMap.put("scoreLevelVo", scoreLevelVo);
        dataMap.put("scoreRatioVo", scoreRatioVo);
        dataMap.put("scoreAvgVo", scoreAvgVo);
        dataMap.put("scorePointVo", scorePointVo);
        return dataMap;
    }

    /**
     * @Title: statScoreLevel
     * @Description: 驾驶员分数等级
     * @author zhangl
     * @param params
     * @param index
     * @return DrvBehaviorScoreLevelVo
     */
    @SuppressWarnings({ "unchecked" })
    public DrvBehaviorScoreLevelVo statScoreLevel(Map<String, Object> params) {
        Map<String, Object> mapCurrent = (Map<String, Object>) this.sqlMapDao.selectOne("driverBehavior.statScoreLevel", params);
        DrvBehaviorScoreLevelVo scoreLevelVo = (DrvBehaviorScoreLevelVo) PubUtil.convertMapToObject(mapCurrent, DrvBehaviorScoreLevelVo.class);
        return scoreLevelVo;
    }

    /**
     * @Title: statScoreRatio
     * @Description: 驾驶员分数比率
     * @author zhangl
     * @param params
     * @param index
     * @return DrvBehaviorScoreRatioVo
     */
    @SuppressWarnings({ "unchecked" })
    public DrvBehaviorScoreRatioVo statScoreRatio(Map<String, Object> params) {
        Map<String, Object> mapCurrent = (Map<String, Object>) this.sqlMapDao.selectOne("driverBehavior.statScoreRatio", params);
        DrvBehaviorScoreRatioVo scoreRatioVo = (DrvBehaviorScoreRatioVo) PubUtil.convertMapToObject(mapCurrent, DrvBehaviorScoreRatioVo.class);
        return scoreRatioVo;
    }

    /**
     * @Title: statScoreAvg
     * @Description: 驾驶员平均分
     * @author zhangl
     * @param params
     * @param index
     * @return DrvBehaviorScoreAvgVo
     */
    @SuppressWarnings({ "unchecked" })
    public DrvBehaviorScoreAvgVo statScoreAvg(Map<String, Object> params) {
        Map<String, Object> mapCurrent = (Map<String, Object>) this.sqlMapDao.selectOne("driverBehavior.statScoreAvg", params);
        DrvBehaviorScoreAvgVo scoreAvgVo = (DrvBehaviorScoreAvgVo) PubUtil.convertMapToObject(mapCurrent, DrvBehaviorScoreAvgVo.class);
        return scoreAvgVo;
    }

    /**
     * @Title: statScorePoint
     * @Description: 驾驶员分数20%临界点
     * @author zhangl
     * @param params
     * @param index
     * @return DrvBehaviorScoreRatioVo
     */
    @SuppressWarnings({ "unchecked" })
    public DrvBehaviorScorePointVo statScorePoint(Map<String, Object> params) {
        Map<String, Object> mapCurrent = (Map<String, Object>) this.sqlMapDao.selectOne("driverBehavior.statScorePoint", params);
        DrvBehaviorScorePointVo pointVo = (DrvBehaviorScorePointVo) PubUtil.convertMapToObject(mapCurrent, DrvBehaviorScorePointVo.class);
        return pointVo;
    }

    /**
     * @Title: statScoreHot
     * @Description: 驾驶员分数 热力
     * @author zhangl
     * @param params
     * @return DrvBehaviorScorePointVo
     */
    @SuppressWarnings({ "unchecked" })
    public Map<String,Object> statScoreHot(Map<String, Object> params) {
        Map<String, Object> returnMap = new HashMap<String, Object>();
        List<DrvBehaviorScoreHotLevelVo> scoreHotLevelVoList = this.getScoreHotLevel(params);

        // params.put("days", getDaysOfMonth(params.get("monthly").toString()));
        List<Map> dataMap = this.sqlMapDao.selectList("driverBehavior.statScoreHot", params);
        List<DrvBehaviorScoreHotVo> scoreHotList = PubUtil.convertListMapToObject(dataMap, DrvBehaviorScoreHotVo.class);

        if(scoreHotList != null && scoreHotList.size() > 0){
            for (DrvBehaviorScoreHotVo scoreHotVo : scoreHotList) {
                if(scoreHotLevelVoList != null && scoreHotLevelVoList.size() > 0){
                    for (DrvBehaviorScoreHotLevelVo scoreLevelVo : scoreHotLevelVoList) {
                        if (scoreHotVo.getAvgScoreHot().compareTo(scoreLevelVo.getScoreFrom()) >= 0 && scoreHotVo.getAvgScoreHot().compareTo(scoreLevelVo.getScoreTo()) <= 0) {
                            scoreHotVo.setScoreType(scoreLevelVo.getScoreType());
                            scoreHotVo.setScoreTypeId(scoreLevelVo.getScoreTypeId());
                        }
                    }
                }
            }
        }
        returnMap.put("levelList", scoreHotLevelVoList);
        returnMap.put("scoreHotList", scoreHotList);
        return returnMap;
    }

    /**
     * @Title: getScoreHotLevel
     * @Description: 驾驶员评分热力等级
     * @author zhangl
     * @param params
     * @return List<DrvBehaviorScoreHotLevelVo>
     */
    @SuppressWarnings({ "unchecked" })
    public List<DrvBehaviorScoreHotLevelVo> getScoreHotLevel(Map<String, Object> params) {
        List<Map> dataMap = this.sqlMapDao.selectList("driverBehavior.getScoreHotLevel",params);
        List<DrvBehaviorScoreHotLevelVo> dataList = PubUtil.convertListMapToObject(dataMap, DrvBehaviorScoreHotLevelVo.class);
        return dataList;
    }

    /**
     * @Title: getDrvImprove
     * @Description: 驾驶员进退步排名
     * @author zhangl
     * @return List<DrvBehaviorImproveVo>
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public List<DrvBehaviorImproveVo> getDrvImproveList(Map<String, Object> params) {
        List<Map> dataMap = this.sqlMapDao.selectList("driverBehavior.getDrvImproveList", params);
        List<DrvBehaviorImproveVo> dataList = PubUtil.convertListMapToObject(dataMap, DrvBehaviorImproveVo.class);
        return dataList;
    }

    /**
     * @Title: getDrvScoreSortList
     * @Description: 驾驶员评分排名
     * @author zhangl
     * @param params
     * @return List<DrvBehaviorSortVo>
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public List<DrvBehaviorScoreSortVo> getDrvScoreSortList(Map<String, Object> params) {
        List<Map> dataMap = this.sqlMapDao.selectList("driverBehavior.getDrvScoreSortList", params);
        List<DrvBehaviorScoreSortVo> dataList = PubUtil.convertListMapToObject(dataMap, DrvBehaviorScoreSortVo.class);
        return dataList;
    }

    /**
     * @Title: getDrvScoreSortPage
     * @Description: 驾驶员评分排名 分页
     * @author zhangl
     * @param params
     * @return Pagination
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public Pagination getDrvScoreSortPage(Map<String, Object> params) {
        Pagination page = this.myBatisPage("driverBehavior.getDrvScoreSortCount", "driverBehavior.getDrvScoreSortPage", params, DrvBehaviorScoreSortVo.class);
        return page;
    }

    /**
     * 
     * @Title:  statBehaviorFeature
     * @Description: 驾驶行为特征待改进
     * @author zhangl
     * @param params
     * @return
     * List<DrvBehaviorSortVo>
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public List<DrvBehaviorFeatureVo> statBehaviorFeature(Map<String, Object> params) {
        Map<String, Object> dateMapCurrent = null;
        try {
            dateMapCurrent = this.convertDate(params.get("dateType").toString(), 1, "03", params.get("lineId").toString());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        params.putAll(dateMapCurrent);
        List<Map> dataMap = this.sqlMapDao.selectList("driverBehavior.statBehaviorFeature", params);
        List<DrvBehaviorFeatureVo> dataList = PubUtil.convertListMapToObject(dataMap, DrvBehaviorFeatureVo.class);
        return dataList;
    }
    
    /**
     * 
     * @Title:  getDrvScoreSortSingle
     * @Description: 驾驶员评分 单个
     * @author zhangl
     * @param params
     * @return
     * DrvBehaviorScoreSingleVo
     */
    @SuppressWarnings({ "unchecked" })
    public DrvBehaviorScoreSortVo getDrvScoreSortSingle(Map<String, Object> params) {
        /*Map<String, Object> mapCurrent = (Map<String, Object>) this.sqlMapDao.selectOne("driverBehavior.getDrvScoreSortSingle", params);
        DrvBehaviorScoreSingleVo scoreSortVo = (DrvBehaviorScoreSingleVo) PubUtil.convertMapToObject(mapCurrent, DrvBehaviorScoreSingleVo.class);
        return scoreSortVo;*/
        DrvBehaviorScoreSortVo scoreSortVo = null;
        List<DrvBehaviorScoreSortVo> list= this.getDrvScoreSortList(params);
        if(list != null && list.size() > 0){
            scoreSortVo = list.get(0);
        }
        return scoreSortVo;
    }
    
    /**
     * 
     * @Title:  statBehaviorFeatureTypeSingle
     * @Description: 驾驶员驾驶行为画像
     * @author zhangl
     * @param params
     * @return
     * DrvBehaviorFeatureTypeVo
     */
    @SuppressWarnings({ "unchecked" })
    public  List<DrvBehaviorFeatureTypeVo> getBehaviorFeatureType(Map<String, Object> params) {
        List<Map> dataMap = this.sqlMapDao.selectList("driverBehavior.getBehaviorFeatureType",params);
        List<DrvBehaviorFeatureTypeVo> dataList = PubUtil.convertListMapToObject(dataMap, DrvBehaviorFeatureTypeVo.class);
        return dataList;
    }
    
    /**
     * 
     * @Title:  getBehaviorFeatureDetail
     * @Description: 驾驶员驾驶行为特征明细
     * @author zhangl
     * @param params
     * @return
     * DrvBehaviorFeatureTypeVo
     */
    @SuppressWarnings({ "unchecked" })
    public List<DrvBehaviorFeatureDetailVo> getBehaviorFeatureDetail(Map<String, Object> params) {
        List<Map> dataMap = this.sqlMapDao.selectList("driverBehavior.getBehaviorFeatureDetail",params);
        List<DrvBehaviorFeatureDetailVo> dataList = PubUtil.convertListMapToObject(dataMap, DrvBehaviorFeatureDetailVo.class);
        return dataList;
    }
    
    /**
     * 
     * @Title:  getBehaviorFeatureCompare
     * @Description: 驾驶员驾驶行为特征比较
     * @author zhangl
     * @param params
     * @return
     * DrvBehaviorFeatureCompareVo
     */
    @SuppressWarnings({ "unchecked" })
    public  Map<String, Object> getBehaviorFeatureCompare(Map<String, Object> params) {
        Map<String, Object> mapCurrent = new HashMap<String, Object>();
        DrvBehaviorModelDataVo modelDataVo = this.getBehaviorModelData(params);
        if(modelDataVo != null){
             String drvFitDist = modelDataVo.getDrvFitDist();//驾驶员该特征Y轴数据集
             String distFitX = modelDataVo.getDistFitX();//特征数据拟合的x轴数据集
             String goodBins = modelDataVo.getGoodBins();//"好"类特征数据分布区间分割集
             String goodDist = modelDataVo.getGoodDist();//"好"类特征区间频次标准化数据集
             String goodDistFit = modelDataVo.getGoodDistFit();//"好"类特征区间频次标准化拟合数据集
             String badBins = modelDataVo.getBadBins();//"差"类数据分布区间分割集
             String badDist = modelDataVo.getBadDist();//"差"类特征区间频次标准化数据集
             String badDistFit = modelDataVo.getBadDistFit(); //"差"类特征区间频次标准化拟合数据集
             
             mapCurrent.put("drvFitDist", drvFitDist==null ? null:drvFitDist.replace("[", "").replace("]", "").split(","));
             mapCurrent.put("distFitX", distFitX==null ? null:distFitX.replace("[", "").replace("]", "").split(","));
             mapCurrent.put("goodBins", goodBins==null ? null:goodBins.replace("[", "").replace("]", "").split(","));
             mapCurrent.put("goodDist", goodDist==null ? null:goodDist.replace("[", "").replace("]", "").split(","));
             mapCurrent.put("goodDistFit", goodDistFit==null ? null:goodDistFit.replace("[", "").replace("]", "").split(","));
             mapCurrent.put("badBins", badBins==null ? null:badBins.replace("[", "").replace("]", "").split(","));
             mapCurrent.put("badDist", badDist==null ? null:badDist.replace("[", "").replace("]", "").split(","));
             mapCurrent.put("badDistFit", badDistFit==null ? null:badDistFit.replace("[", "").replace("]", "").split(","));
        }
        return mapCurrent;
    }
    
    /**
     * 
     * @Title:  getBehaviorModelData
     * @Description: 驾驶行为特征标杆数据
     * @author zhangl
     * @param params
     * @return
     * DrvBehaviorModelDataVo
     */
    @SuppressWarnings({ "unchecked" })
    public DrvBehaviorModelDataVo getBehaviorModelData(Map<String, Object> params) {
        Map<String, Object> mapCurrent = (Map<String, Object>) this.sqlMapDao.selectOne("driverBehavior.getBehaviorModelData", params);
        DrvBehaviorModelDataVo modelDataVo = (DrvBehaviorModelDataVo) PubUtil.convertMapToObject(mapCurrent, DrvBehaviorModelDataVo.class);
        return modelDataVo;
    }
    
    /**
     * 
     * @Title:  getBehaviorReport
     * @Description: 驾驶行为打印
     * @author zhangl
     * @param params
     * @return
     * Map<String,Object>
     */
    @SuppressWarnings({ "unchecked" })
    public  Map<String, Object> getBehaviorReport(Map<String, Object> params) {
        Map<String, Object> dataMap = new HashMap<String, Object>();
        DrvBehaviorScoreSortVo scoreSortVo = this.getDrvScoreSortSingle(params);
        List<DrvBehaviorFeatureTypeVo> featureTypeVos = this.getBehaviorFeatureType(params);
        List<DrvBehaviorFeatureDetailVo> featureDetailVos = this.getBehaviorFeatureDetail(params);
        
        if(featureTypeVos != null && featureTypeVos.size() > 0 && featureDetailVos != null && featureDetailVos.size() > 0){
            for (DrvBehaviorFeatureTypeVo featureTypeVo : featureTypeVos) {
                for (DrvBehaviorFeatureDetailVo featureDetailVo : featureDetailVos) {
                    if (featureDetailVo.getFeatureType().equals(featureTypeVo.getFeatureType())) {
                        featureTypeVo.getFeatureDetailList().add(featureDetailVo);
                    }
                }
            }
        }
        TimeRangeVo timeRangeVo = this.getTimeRange(params);
        dataMap.put("timeRangeVo", timeRangeVo);
        dataMap.put("scoreSortVo", scoreSortVo);
        dataMap.put("featureTypeVos", featureTypeVos);
        return dataMap;
    }
    
    /**
     * 
     * @Title:  getBehaviorScoreTrend
     * @Description: 驾驶员分数趋势
     * @author zhangl
     * @param params
     * @return
     * List<DrvBehaviorScoreAvgVo>
     */
    @SuppressWarnings({ "unchecked" })
    public List<DrvBehaviorScoreTrendVo> getBehaviorScoreTrend(Map<String, Object> params) {
        Map<String, Object> dateMapCurrent = null;
        try {
            dateMapCurrent = this.convertDate(params.get("dateType").toString(), 1, "02", params.get("lineId").toString());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        params.putAll(dateMapCurrent);
        List<Map> dataMap = this.sqlMapDao.selectList("driverBehavior.getBehaviorScoreTrend",params);
        List<DrvBehaviorScoreTrendVo> dataList = PubUtil.convertListMapToObject(dataMap, DrvBehaviorScoreTrendVo.class);
        return dataList;
    }
    
    /**
     * 
     * @Title:  getBehaviorScoreWeek
     * @Description: 驾驶员一周分数
     * @author zhangl
     * @param params
     * @return
     * List<DrvBehaviorScoreWeekVo>
     */
    @SuppressWarnings({ "unchecked" })
    public List<DrvBehaviorScoreTrendVo> getBehaviorScoreWeek(Map<String, Object> params) {
        if(params.get("endTime")  != null ){
            try {
                params.put("beginTime", DateTool.calculateByDate(params.get("endTime").toString(), -6));
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        //params.put("isWeek", "true");//时间格式化周
        List<Map> dataMap = this.sqlMapDao.selectList("driverBehavior.getBehaviorScoreWeek",params);
        List<DrvBehaviorScoreTrendVo> dataList = PubUtil.convertListMapToObject(dataMap, DrvBehaviorScoreTrendVo.class);
        return dataList;
    }

}
